<?php
if (!function_exists('file_put_contents')) {
    function file_put_contents($filename, $data) {
        $f = @fopen($filename, 'w');
        if (!$f) {
            return false;
        } else {
            $bytes = fwrite($f, $data);
            fclose($f);
            return $bytes;
        }
    }
}

class Sb_Cache
{
	
	var $FILE_NAME;
	var $ROOT_DIR;
	
	function Sb_Cache()
	{
		ob_start("ob_gzhandler");
		$this->ROOT_DIR = 'Cache';
		$this->FILE_NAME = ltrim($_SERVER['SCRIPT_NAME'],'/');
		$this->FILE_NAME = str_replace('.php', '.html', $this->FILE_NAME);
		if(!is_dir($this->ROOT_DIR))
			@mkdir($this->ROOT_DIR, 0777);
	}
	
	function get($key = null)
	{
		if(null == $key)
			$key = $this->FILE_NAME;
		$filePath = $this->ROOT_DIR.DIRECTORY_SEPARATOR.$key;
		$return = false;
		if(file_exists($filePath))
			$return = file_get_contents($filePath);
		return $return;
	}
	
	function set($val,$key = null)
	{
		if(null == $key)
			$key = $this->FILE_NAME;
		$filePath = $this->ROOT_DIR.DIRECTORY_SEPARATOR.$key;
		@file_put_contents($filePath,$val);
	}
	
	function clear($key)
	{
		
	}
	
	function clearAll()
	{
	
	}
}